﻿using System;

namespace _2023_4_14飞行棋
{
    class Program
    {
        static string[] graphics = { "口", "Ｏ", "Ｘ", "Ｐ", "＠", "<>" };
        static int[] luckturn = { 6, 25, 77, 44, 12 };
        static int[] landMine = { 2, 11, 18,35,41, 57 };
        static int[] pause = { 10, 20, 30, 40 };
        static int[] timeTunnel = { 11, 22, 33, 45, 80 };
        static int[] playerGround = new int[100];
        static string[] playerNames = new string[2];
        static int[] playerPos = { 0, 0 };
        static int[] playerPuse = { 0, 0 };
        static void Main(string[] args)
        {
            Random rand = new Random();
            GameShow();
            #region 玩家名字输入
            while (true)
            {
                Console.WriteLine("请输入玩家A的名字");
                string input = Console.ReadLine();
                if(input=="")
                {
                    Console.WriteLine("名字不能为空，请重新输入");
                    continue;
                }
                playerNames[0] = input;
                break;
            }
            while(true)
            {
                Console.WriteLine("请输入玩家B的名字");
                string input = Console.ReadLine();
                if(input=="")
                {
                    Console.WriteLine("名字不能为空，请重新输入");
                    continue;

                }
                if(input==playerNames[0])
                {
                    Console.WriteLine("名字与A重复，请重新输入");
                    continue;
                }
                playerNames[1] = input;
                break;
            }
            #endregion
            Console.WriteLine("{0}的士兵用A表示，{1}的士兵用B表示", playerNames[0], playerNames[1]);
            Console.WriteLine("请按下任意键继续");
            Console.ReadKey(true);
            Console.Clear();
            InIt();
            TotalShow();
            while(playerPos[0]<99&&playerPos[1]<99)
            {
                if (playerPuse[0] == 0)
                {
                    Console.WriteLine("请按任意键继续");
                    Console.ReadKey(true);
                    Console.WriteLine("{0}的回合", playerNames[0]);
                    Game(0, rand);
                    Console.WriteLine("请按任意键继续");
                    Console.ReadKey();
                    Console.Clear();
                    TotalShow();
                    if (playerPos[0] == 99)
                    {
                        break;
                    }
                }
                else
                {
                    playerPuse[0] = 0;
                }
                if (playerPuse[1] == 0)
                {
                    Console.WriteLine("请按任意键继续");
                    Console.ReadKey(true);
                    Game(1, rand);
                    Console.WriteLine("请按任意键继续");
                    Console.ReadKey();
                    Console.Clear();
                    TotalShow();
                    if(playerPos[1]==99)
                    {
                        break;
                    }
                }
                else
                {
                    playerPuse[1] = 0;
                }
            }
            Console.WriteLine("{0},赢得了比赛", playerPos[0] > playerPos[1] ? playerNames[0] : playerNames[1]);



        }
        static void GameShow()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("******************************");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("******************************");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("**********飞行棋游戏**********");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("******************************");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("******************************");
        }
        /// <summary>
        /// 初始化数组即将那些如地雷之类的东西放进去
        /// </summary>
        static  void InIt()
        {
            for(int i=0;i<luckturn.Length;i++)
            {
                playerGround[luckturn[i]] = 1;
            }
            for(int i=0;i<landMine.Length;i++)
            {
                playerGround[landMine[i]] = 2;
            }
            for(int i=0;i<pause.Length;i++)
            {
                playerGround[pause[i]] = 3;
            }
            for(int i=0;i<timeTunnel.Length;i++)
            {
                playerGround[timeTunnel[i]] = 4;
            }

        }
        /// <summary>
        /// 里面没有换行单纯打印
        /// </summary>
        /// <param name="i"></param>
        static void DrawLine(int i)
        {
            if(playerPos[0]==playerPos[1]&&playerPos[0]==i)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(graphics[5]);
                return;
            }
            if(playerPos[0]==i)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("Ａ");
                return;
            }
            if(playerPos[1]==i)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Ｂ");
                return;
            }
            switch(playerGround[i])
            {
                case 0:
                    Console.ForegroundColor = ConsoleColor.White;
                    break;
                case 1:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
                case 2:
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;
                case 3:
                    Console.ForegroundColor = ConsoleColor.Blue;
                    break;
                case 4:
                    Console.ForegroundColor = ConsoleColor.DarkMagenta;
                    break;
                case 5:
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    break;

            }
            Console.Write(graphics[playerGround[i]]);
            
        }
        /// <summary>
        /// 第二个要出现的东西
        /// </summary>
        static void TheSecondShow()
        {
            Console.WriteLine("图例：幸运轮盘: Ｏ    地雷：Ｘ    暂停：Ｐ  时空隧道：＠");
        }
        /// <summary>
        /// 结合游戏头游戏体的函数 其最后一行是有一个换行的直接开始写
        /// </summary>
        static void TotalShow()
        {
            #region 游戏的头
            TheSecondShow();
            #endregion
            #region 第一横行
            for (int i = 0; i < 30; i++)
            {
                DrawLine(i);
            }
            #endregion
            Console.WriteLine();
            #region 第一竖
            for (int j = 30; j <= 34; j++)
            {
                for (int i = 0; i < 29; i++)
                {
                    Console.Write("  ");
                }
                DrawLine(j);
                Console.WriteLine();
            }
            #endregion
            //上面有一个换行
            #region 第二行
            for (int i = 64; i >= 35; i--)
            {
                DrawLine(i);
            }
            #endregion
            Console.WriteLine();
            #region 第二竖
            for (int i = 65; i <= 69; i++)
            {
                DrawLine(i);
                for (int j = 0; j < 29; j++)
                {
                    Console.Write("  ");
                }
                Console.WriteLine();
            }
            #endregion
            //上面有一个换行
            #region 最后一行
            for (int i = 70; i <= 99; i++)
            {
                DrawLine(i);
            }
            #endregion
            Console.WriteLine();
        }
        /// <summary>
        /// 游戏逻辑主体
        /// </summary>
        /// <param name="i">表示到谁的回合</param>
        /// <param name="rand">产生随机数</param>
        static void Game(int i,Random rand)
        {
            int steps = rand.Next(1, 7);
            playerPos[i] += steps;
            if (playerPos[i] > 99)
            {
                playerPos[i] = 99;
            }
            if (playerPos[i] < 0)
            {
                playerPos[i] = 0;
            }
            #region 当后一个人追上前一个人时逻辑
            if (playerPos[0] == playerPos[1])
            {
                Console.WriteLine("{0}被{1}打回去了,{0}退6步", playerNames[1 - i], playerNames[i]);
                playerPos[1 - i] -= 6;
                if (playerPos[1 - i] < 0)
                {
                    playerPos[1 - i] = 0;
                }
            }
            #endregion

            switch (playerGround[playerPos[i]])
            {
                case 0:
                    Console.WriteLine(" {0}前进了{1}步，无事发生", playerNames[i], steps);
                    break;
                case 1:
                    #region 幸运轮盘逻辑
                    Console.WriteLine("{0}前进了{1}步触发幸运轮盘",playerNames[i],steps);
                    Console.WriteLine("1.交换位置  2.轰炸对方(即对方退6步)");
                    int input;
                    while (true)
                    {
                        Console.WriteLine("请输入");
                        if (int.TryParse(Console.ReadLine(), out input) == false
                            || (input < 1 || input > 2))
                        {
                            Console.WriteLine("输入错误");
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (input == 1)
                    {
                        int temp = playerPos[i];
                        playerPos[i] = playerPos[1 - i];
                        playerPos[1-i] = temp;

                    }
                    else
                    {
                        playerPos[1 - i] -= 6;
                        if (playerPos[1 - i] < 0)
                        {
                            playerPos[1-i] = 0;
                        }
                    }
                    break;
                #endregion
                case 2:
                    #region 地雷逻辑
                    Console.WriteLine("{0}前进了{1}步踩到了地雷,{0}后退6步", playerNames[i],steps);
                    playerPos[i] -= 6;
                    if (playerPos[i] < 0)
                    {
                        playerPos[i] = 0;
                    }
                    break;
                #endregion
                case 3:
                    #region 暂停逻辑
                    Console.WriteLine("{0}前进了{1}步暂停一个回合", playerNames[i],steps);
                    playerPuse[i]++;
                    break;
                #endregion
                case 4:
                    #region 时空隧道逻辑
                    Console.WriteLine("恭喜{0}进入了时空隧道加6步",playerNames[i]);
                    playerPos[i] += 6;
                    if (playerPos[i] > 99)
                    {
                        playerPos[i] = 99;
                    }
                    if (playerPos[0] == playerPos[1])
                    {
                        Console.WriteLine("{0}被{1}打回去了,{0}退6步", playerNames[1-i], playerNames[i]);
                        playerPos[1-i] -= 6;
                        if (playerPos[1-i] < 0)
                        {
                            playerPos[1-i] = 0;
                        }
                    }
                    break;
                    #endregion
            }
            
        }
       



    }
}
